// 讲解系统的轻量全局状态（不依赖外部库）
export type NarrationStatus = 'idle' | 'arming' | 'playing' | 'cooldown';

export interface TriggerSpec {
  radius: number;
  viewAngle: number;
  dwellMs: number;
  cooldownMs: number;
}

export interface ArtworkNarration {
  id: string;
  title: string;
  subtitle: string;
  ttsText: string;
  ttsLang?: string;
  voiceId?: string;
  speed?: number;
  pitch?: number;
  trigger: TriggerSpec;
  playback: { autoplay: boolean; ducking: number; loop: boolean };
  cacheKey?: string;
  audioUrl?: string;
}

export interface RegisteredZone {
  id: string;
  position: [number, number, number];
  normal: [number, number, number];
  width: number;
  height: number;
}

export const narrationStore = {
  data: new Map<string, ArtworkNarration>(),
  zones: new Map<string, RegisteredZone>(),
  status: 'idle' as NarrationStatus,
  currentId: '' as string,
  lastEndAt: 0,
  readyId: '' as string,
  autoMode: true,
};

export function loadNarrations(payload: ArtworkNarration[]) {
  narrationStore.data.clear();
  payload.forEach(item => narrationStore.data.set(item.id, item));
}

export function registerZone(zone: RegisteredZone) {
  narrationStore.zones.set(zone.id, zone);
}

export function unregisterZone(id: string) {
  narrationStore.zones.delete(id);
}


